﻿@{
    ViewData["Title"] = "UpdateSuppliers";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <link rel="stylesheet" href="~/libs/layui-v2.5.6/layui/css/layui.css">
    <script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
</head>
<body>
    <input type="hidden" id="id" name="id" class="layui-input" value="@ViewBag.id">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">供应商编码</label>
            <div class="layui-input-block">
                <input type="text" id="supplierManagementCode" name="supplierManagementCode" lay-verify="required" placeholder="请输入供应商编码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">供应商名称</label>
            <div class="layui-input-block">
                <input type="text" id="supplierName" name="supplierName" lay-verify="required" placeholder="请输入供应商名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">供应商简称</label>
            <div class="layui-input-block">
                <input type="text" id="supplierAbbreviation" name="supplierAbbreviation" lay-verify="required" placeholder="请输入供应商简称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">供应商等级</label>
            <div class="layui-input-block">
                <select id="supplierGrade" name="supplierGrade" lay-filter="aihao" lay-verify="required">
                    <option value=""></option>
                    <option value="优质供应商">优质供应商</option>
                    <option value="正常" selected>正常</option>
                    <option value="重点关注">重点关注</option>
                    <option value="劣质供应商">劣质供应商</option>
                    <option value="黑名单">黑名单</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">供应商评分</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input lay-verify="required" type="number" id="supplierScore" name="supplierScore" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">供应商电话</label>
            <div class="layui-input-block">
                <input type="text" id="supplierPhone" name="supplierPhone" lay-verify="required" placeholder="请输入供应商电话" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="state" value="true" title="是" checked>
                <input type="radio" name="state" value="false" title="否">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="~/libs/jquery/jquery.js"></script>
    <script>
           $(function () {
            getsupplierById()
            })

        function getsupplierById() {
            $.ajax({
                url: "/Suppliers/SelectUpdate",
                data: { id: @ViewBag.id },
                type: "get",
                datatype: "json",
                success: function (res) {
                    $("#id").val(res.data.id);
                    $("#supplierManagementCode").val(res.data.supplierManagementCode)
                    $("#supplierName").val(res.data.supplierName)
                    $("#supplierAbbreviation").val(res.data.supplierAbbreviation)
                    $("#supplierGrade").val(res.data.supplierGrade)
                    $("#supplierScore").val(res.data.supplierScore)

                    $("#supplierPhone").val(res.data.supplierPhone)

                    $("[name='state'][value=" + res.data.state + "]").prop("checked", true);
                         layui.form.render("radio");
                         // 下拉框渲染
                         layui.form.render('select');
                }
            })
         layui.use(['form', 'laydate', 'util'], function(){
           var form = layui.form;
           var layer = layui.layer;
           var laydate = layui.laydate;
           var util = layui.util;
           // 提交事件
           form.on('submit(demo1)', function(data){
               console.log(22222)
             var field = data.field; // 获取表单字段值
             field.id = @ViewBag.id;
             console.table(1111111,field);
             $.ajax({
                 url:'/Suppliers/Update',
                 type:'post',
                 async:false,
                 data:field,
                 datatype:'json',
                 success:function(res){
                      if(res.code>0){
                      var index = parent.layer.getFrameIndex(window.name); /* 先得到当前iframe层的索引 */
                             parent.layer.close(index); /* 再执行关闭 */
                              parent.location.reload(); /* 刷新父页面，即列表页面 */
                           layer.alert('修改成功');

                      }
                       parent.location.reload(); /* 刷新父页面，即列表页面 */
                        alert('修改成功');
                 }
             })
             return false; // 阻止默认 form 跳转
            });

        });
        }
    </script>
</body>
</html>



